import { loginApi } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'

export default {
  namespaced: true,
  state: {
    token: getToken()
  },
  mutations: {
    setToken(state, payload) {
      state.token = payload
      setToken(payload)
    },
    removeToken(state) {
      state.token = null
      removeToken()
    }
  },
  actions: {
    async loginAction(context, data) {
      // console.log(data)
      const res = await loginApi(data)
      console.log('~ ~ res', res)
      context.commit('setToken', res)
    }
  }
}
